<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function merge(target, ...sources) {
      sources.forEach((source) => {
        Object.keys(source).forEach((key) => {
          const value = source[key];
          if (typeof value == "object" && value != null) {
            let newTarget = null;
            if (value instanceof Array) {
              newTarget = target[key] || [];
            } else {
              newTarget = target[key] || {};
            }
            target[key] = this.merge(newTarget, value);
          } else {
            target[key] = value;
          }
        });
      });
      return target;
    };

    const target = {};
    const data = { name: 'ck', school: { code: '007', name: '国防' } };
    merge(target, data)
  </script>
</body>

</html>